import React,{useReducer} from 'react'
import {Switch,Route,Redirect } from "react-router-dom"
import Login from "./pages/Login/Login"
import Register from "./pages/Register/Register"
import Index from "./pages/Index/Index"
import List from "./pages/List/List"
import Detail from "./pages/Detail/Detail" 
import Search from "./pages/Search/Search" 
import {reducer,initState} from "./reducer/app"
//创建上下文
export const MyContext= React.createContext()
export default function App() {
  const [state,dispatch] = useReducer(reducer,initState)
  return (
    <div className='app'>
      {/* 传递数据 */}
       <MyContext.Provider value={{state,dispatch}}>
      {/* switch 路由规则 */}
      <Switch>
        {/* Route 路由规则  */}
        <Route path="/login" component={Login}></Route>
        <Route path="/register" component={Register}></Route>
        <Route path="/index" component={Index}></Route>
        <Route path="/list" component={List}></Route>
        <Route path="/detail/:id" component={Detail}></Route>
        <Route path="/search" component={Search}></Route>
        <Redirect to="/login"></Redirect>
      </Switch>
      </MyContext.Provider>
    </div>
  )
}

